]> dgit.raspbian.org Git - grub2.git/commitdiff
fix-for-gcc-2.16-4
authorGRUB Maintainers <pkg-grub-devel@alioth-lists.debian.net>
Wed, 23 Sep 2026 20:39:45 +0000 (21:39 +0100)
committerSteve McIntyre <93sam@debian.org>
Wed, 23 Sep 2026 20:39:45 +0000 (21:39 +0100)
commit 675d8581037dc8996cf6db21a61d26e28f7d44c1
Author: Nicholas Vinson <nvinson234@gmail.com>
Date:   Tue Feb 24 19:48:39 2026 -0500

    osdep/linux/ofpath: Update strstr() calls

    With C23, strstr() returns a "const char *" if its first argument is
    "const char *", and these changes are implemented in glibc-2.43.

    As a result, the first strstr() call in check_sas() now returns a "const
    char *" instead of "char *" because sysfs_path is a "const char *". This
    triggers a "discards qualifiers" warning, that is later promoted to an
    error and ultimately causes the build to fail.

    To fix the issue, this patch converts "ed", the pointer that stores
    strstr()'s return value, to a "const char *". Removes the xstrdup()
    call and cleans up the rest of the function by updating the *printf()
    calls and using pointer arithmetic to compute lengths instead of strlen().

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic upstream
Gbp-Pq: Name fix-for-gcc-2.16-4.patch

grub-core/osdep/linux/ofpath.c

index 24a4d5c8dcb53756123b3eb54211fd479795e41b..0ebfea44cb61a976fa50ceac0ab2637332243a56 100644 (file)
@@ -488,8 +488,11 @@ check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id)
 static void
 check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
 {
-  char *ed = strstr (sysfs_path, "end_device");
-  char *p, *q, *path;
+  const char *ed = strstr (sysfs_path, "end_device");
+  int p_len;
+  int ed_len;
+  const char *q;
+  char *path;
   char phy[21];
   int fd;
   size_t path_size;
@@ -498,20 +501,16 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
     return;
 
   /* SAS devices are identified using disk@$PHY_ID */
-  p = xstrdup (sysfs_path);
-  ed = strstr(p, "end_device");
-  if (!ed)
-    return;
-
   q = ed;
   while (*q && *q != '/')
     q++;
-  *q = '\0';
+  p_len = (int) (q - sysfs_path);
+  ed_len = (int) (q - ed);
 
-  path_size = (strlen (p) + strlen (ed)
-              + sizeof ("%s/sas_device/%s/phy_identifier"));
+  path_size = (p_len + ed_len + sizeof ("%s/sas_device/%s/phy_identifier"));
   path = xmalloc (path_size);
-  snprintf (path, path_size, "%s/sas_device/%s/phy_identifier", p, ed);
+  snprintf (path, path_size, "%.*s/sas_device/%.*s/phy_identifier", p_len,
+           sysfs_path, ed_len, ed);
   fd = open (path, O_RDONLY);
   if (fd < 0)
     grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
@@ -524,7 +523,8 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
 
   sscanf (phy, "%d", tgt);
 
-  snprintf (path, path_size, "%s/sas_device/%s/sas_address", p, ed);
+  snprintf (path, path_size, "%.*s/sas_device/%.*s/sas_address", p_len,
+           sysfs_path, ed_len, ed);
   fd = open (path, O_RDONLY);
   if (fd < 0)
     grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
@@ -535,7 +535,6 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
   sscanf (phy, "%lx", sas_address);
 
   free (path);
-  free (p);
   close (fd);
 }